<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<title>医诺云检</title>
		<meta http-equiv="expires" content="0">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<link rel="stylesheet" href="css/reset.css" />
		<link rel="stylesheet" href="css/mui.min.css" />
		<link rel="stylesheet" href="css/cmms.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/login.css" />
		<script src="js/vconsole.min.js"></script>
	</head>
	<body>
		<div class="mui-content logBg" id='login' v-cloak>
			<div class="login">
				<div class="center">
				  	<img class="yinuo" src="img/yinuo.png" alt="医诺业务端" />
				</div>
				<!-- <div class="center company-name">
				  	<img src="img/sale.png" alt="" />
				</div> -->
			</div>
		  
		  <div class="loginContainer center">
				<div class="mui-input-row">
				    <input type="tel" class="mui-input-clear" placeholder="请输入手机号码" v-model="phone">
				</div>
				<div class="mui-input-row">
				    <input type="tel" placeholder="请输入验证码" v-model="vCode">
				    <button class="abs getCode" @tap='getCode' :disabled="vCodeBtn">{{codeText}}</button>
				</div>
				<div class="btn">
				    <button type="button" @tap='login'>登 录</button>
				</div>
		  </div>
		</div>
		
		<script src="js/mui.min.js"></script>
		<script src="js/vue.js"></script>
		<script src="js/cmms.js?time=333"></script>
		<script>
			new Vue({
				el:'#login',
				data:{
					phone:'',
					vCode:'',//验证码
					vCodeBtn:false,//获取验证码按钮
					codeText:'立即获取',
					timer:'',
					vCodeBtn:false,
					code:'',
					state:''
				},
				mounted(){
//					var vConsole = new VConsole();
					AT.muiAjax('/passport/getLoginUser','post',{
					},function(realData){
						location.href = 'pages/sale/index.html';
					});
					this.getUrl();
				},
				beforeDestroy:function(){
					clearInterval(this.timer)
				},
				methods:{
					/*获取微信端URI后的code和state*/
					getUrl(){
						let _this=this;
						var url = location.search; //获取url中"?"符后的字串    
						var theRequest = new Object();  
//						console.log(url);
					   	if (url.indexOf("?") != -1) {   
					      var str = url.substr(1);  
//					      console.log(str);
					      strs = str.split("&");  
					      for(var i = 0; i < strs.length; i ++) {   
					         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
					      } 
					   	}   
					   	console.log(theRequest);
					   	_this.code = theRequest.code;
					   	_this.state = theRequest.state;
					},
					//验证码
					getCode:function(){
						let _this = this;
						if(_this.phone==''){
							mui.alert('请输入手机号');
							return false;
						}
						AT.muiAjax('/common/common/sendMessage','post',{
							mobile:_this.phone
						},function(realData){
							console.log(realData);
						});
						let time = 60;
						_this.vCodeBtn = true;
						_this.timer = setInterval(function(){
							_this.codeText = '重新获取('+time+')S';
							time --;
							if(time<0){
								clearInterval(_this.timer);
								_this.vCodeBtn = false;
								_this.codeText = '获取验证码';
							}
						},1000)
					},
					login:function(){
						let _this = this;
						if(_this.phone==''){
							mui.alert('请输入手机号');
							return false;
						}
						if(_this.vCode==''){
							mui.alert('请输入验证码');
							return false;
						}
//						AT.muiAjax('/passport/login','post',{
//							appType :"3",
//							mobile:_this.phone,
//							password:_this.vCode,
//							userType:"2" 
//						},function(realData){
//							localStorage.setItem('sale_token',realData.token);
//							window.location.href = 'pages/sale/index.html';
//						});

						AT.muiAjax('/passport/mobileLogin','post',{
								wechatAppId:_this.state,
								appType :"3",
								mobile:_this.phone,
								oauthCode:_this.code,
								smsCode:_this.vCode,
								userType:"2" 
						},function(realData){
							localStorage.setItem('state',_this.state);
							localStorage.setItem(_this.state+'_sale_token',realData.token);
							localStorage.setItem('roamFlag',false);
							location.href = 'pages/sale/index.html';
						});
					}
				}
			})
		
		</script>
	</body>
</html>
